﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace TSPquestEDITOR
{
    public partial class basic_info : Form
    {
        public void preload_item_list(object sender, DoWorkEventArgs e)
        {
            SqlConnection qCon = new SqlConnection(connectionString);

            //Update the Total Progress of Preloading
            preload_worker.ReportProgress(10);

            try
            {
                qCon.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            SqlCommand sqlCmd = new SqlCommand("SELECT value, id FROM dbo.StringResource SRES INNER JOIN dbo.ItemResource IRES on IRES.name_id = SRES.code WHERE SRES.value NOT LIKE '%??%' AND SRES.value NOT LIKE '%for test%' ORDER BY id ASC", qCon);

            adapter.SelectCommand = sqlCmd;
            adapter.Fill(item_list);
            adapter.Dispose();
           
            qCon.Close();

            //Quest Objectives need independant selection lists
            //So lets create 4 additional copies of the dbo.ItemResource 
            item_list1 = item_list.Copy();
            item_list2 = item_list.Copy();
            item_list3 = item_list.Copy();
            item_list4 = item_list.Copy();
            
            //Since quest_def_rew IS ALWAYS AN ITEM
            //Lets bind it now
            this.BeginInvoke((Action)delegate()
            {
                quest_def_rew_name_box.DataSource = item_list4.Tables[0];
                quest_def_rew_name_box.DisplayMember = "value";
                quest_def_rew_name_box.ValueMember = "id";
                quest_def_rew_name_box.ResetText();
            });
        }

        public void preload_monster_list(object sender, DoWorkEventArgs e)
        {
                SqlConnection qCon = new SqlConnection(connectionString);

                //Update the Total Progress of Preloading
                preload_worker.ReportProgress(10);

                try
                {
                    qCon.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            SqlCommand sqlCmd = new SqlCommand("SELECT value, id FROM dbo.StringResource SRES INNER JOIN dbo.MonsterResource MRES on MRES.name_id = SRES.code WHERE SRES.value NOT LIKE '%??%' AND SRES.value NOT LIKE '%for test%' ORDER BY id ASC", qCon);

            adapter.SelectCommand = sqlCmd;
            adapter.Fill(monster_list);
            adapter.Dispose();

            qCon.Close();

            monster_list2 = monster_list.Copy();
            monster_list3 = monster_list.Copy();
        }

        public void preload_skill_list(object sender, DoWorkEventArgs e)
        {
            SqlConnection qCon = new SqlConnection(connectionString);

            //Update the Total Progress of Preloading
            preload_worker.ReportProgress(10);

            try
            {
                qCon.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            SqlCommand sqlCmd = new SqlCommand("SELECT value, id FROM dbo.StringResource SRES INNER JOIN dbo.SkillResource SKRES on SKRES.text_id= SRES.code WHERE SRES.value NOT LIKE '%??%' AND SRES.value NOT LIKE '%for test%' ORDER BY id ASC", qCon);

            adapter.SelectCommand = sqlCmd;
            adapter.Fill(skill_list);
            adapter.Dispose();

            qCon.Close();

            skill_list2 = skill_list.Copy();
            skill_list3 = skill_list.Copy();
        }
    }
}
